

var cookie = {
  set: function (name, value, time) {
    document.cookie = name + '=' + value + '; max-age=' + time;
    return this;
  },
  remove: function (name) {
    return this.setCookie(name, '', -1);
  },
  get: function (name, callback) {
    var allCookieArr = document.cookie.split('; ');
    for (var i = 0; i < allCookieArr.length; i++) {
      var itemCookieArr = allCookieArr[i].split('=');
      if (itemCookieArr[0] === name) {
        return itemCookieArr[1]
      }
    }
    return undefined;
  }
}

function isReservedWords(str){
  var a = [
    'break','else','new','var','case','finally','return','void','catch','for','switch','while','continue','function','this','with','default','if','throw','delete','in','try','do','instranceof','typeof'
  ];//ECMAScription的全部关键字
  var b = [
    'abstract','enum','int','short','boolean','export','interface','static','byte','extends','long','super','char','final','native','synchronized','class','float','package','throws','const','goto','private ','transient','debugger','implements','protected ','volatile','double','import','public'
  ];//ECMA第3版定义的全部_保留字
  var c = [
    'let','const'
  ];//ES2015新增关键字
  var d = [
    'Infinity','arguments'
  ]
  return [].concat(a,b,c,d,['true','false','null']).includes(str);
}


// try {
//   something
// }catch(err) {
//   window.location.href =
//   "http://www.baidu.com/search?q=[js]+" +
//   err.message;
// }

// 关于去空格trim
console.log("       Ru noob        ".trim())//Ru noob
console.log("s s".trim())//s s
// 上述测试用例可以证明原生的trim各种不好用……IE9才支持的也就那样……
// 本来没怎么关注这个问题的，今天突然有个想法，将某个“句子”转驼峰写法，这下真的炸锅了。
function 菜鸟Trim(x) {
  return x.replace(/^\s+|\s+$/gm,'');
}
console.log( 菜鸟Trim("       Ru noob        ") )//Ru noob
console.log( 菜鸟Trim('s s') )//s s
// 上述用来替换的正则也不怎样
// 后面自己试了下，下面这个比较好用
function testTrim(str){
  return str.replace(/\s+/g,"");
}

/*以下未测*/
function 驼峰转连字(str){
  return str.replace(/([A-Z])/g,"-$1").toLowerCase();
}

function 连字转驼峰(str){
  return str.replace(/\/-(/w)/g, function(all, letter){
    return letter.toUpperCase();
  });
}
